/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pio.action.administrador.instituciones;

import DBMS.DataBaseManager;
import clases.Coordinador;
import clases.Institucion;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author tamerdark
 */
public class Agregar extends DispatchAction {
    
    public ActionForward save(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        request.setAttribute("instituciones", Institucion.getAll());
        Institucion c = (Institucion) form;
        DataBaseManager dbms = DataBaseManager.getInstance();
        if (dbms.agregarInstitucion(c)) {
            c.cleanAttributes();
            c.setMensaje("Institucion agregado");
            return mapping.findForward("success");
        } else {
            c.setMensaje("No se pudo agregar la Institucion");
            return mapping.findForward("failure");
        }
    }
    
    public ActionForward populate(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        System.out.println("DSAdad");
        request.setAttribute("instituciones", Institucion.getAll());
        return mapping.findForward("success");
    }
}
